/*
 * @Description: 字典列表
 * @Author: Rfan
 * @Date: 2022-05-28 14:25:10
 * @LastEditTime: 2022-06-20 17:23:02
 */

import { Menu } from 'antd';
import type { SelectInfo } from 'rc-menu/lib/interface';
import { useDictionaryContext } from '../contexts/DictionaryContext';
import { selectItemByKey } from '@/utils/list';

const DicNav = () => {
  console.log('ATLevelNav');

  const { selectAT, dictionaryList, selectDictionary, setDictionary } = useDictionaryContext();

  const menuSelected = ({ key }: SelectInfo) => {
    setDictionary(selectItemByKey(parseInt(key, 10), dictionaryList));
  };

  return (
    <>
      {dictionaryList.length > 0 && (
        <Menu
          mode="inline"
          selectedKeys={[`${selectDictionary.id}`]}
          style={{ width: 200 }}
          onSelect={menuSelected}
        >
          {dictionaryList.map((item: any) => (
            <Menu.Item key={item.id}>
              {item.name}[{item.code}]
            </Menu.Item>
          ))}
        </Menu>
      )}
    </>
  );
};

export default DicNav;
